namespace Mafool.Core;

public static partial class Extends
{
    /// <summary>
    /// 时间戳
    /// </summary>
    /// <param name="t"></param>
    /// <returns></returns>
    public static long ConvertToTimestamp(this DateTime t   )
    {
        //DateTime.UtcNow = dateTime;
        //TimeSpan.FromMinutes( 0 );

        return (long)(t.ToUniversalTime() -DateTime.UnixEpoch).TotalSeconds;
    }

    /// <summary>
    /// 时间戳(秒)转时间
    /// </summary>
    public static DateTime UnixTimeStampToDateTime(this long unixTimeStamp)
    {
        return DateTime.UnixEpoch.AddSeconds(unixTimeStamp);
    }

    /// <summary>
    /// 格式化时间格式 yyyy-MM-dd hh:mm:ss
    /// </summary>
    /// <returns></returns>
    public static string Zh(this DateTime date, string format = "yyyy-MM-dd hh:mm:ss")
    {
        return date.ToString(format);
    }
}